* Author: Anina Schwarzenbach
* generated October 2014
* last review August 2020

clear
use "../../STATAfiles/S11_workfile_20150327_mbv2.dta"
set more off

*load ADOS
sysdir set PERSONAL "../../../ados"

*******************************************************************************************
*RECODINGS OF VARIABLES - GERMANY
******************************************************************************************



*** STRUCTURE ***

*** INDIVIDUAL DEMOGRAPHICS 
*** FAMILY ENVIRONMENT 
*** SOCIAL ENVIRONMENT 
*** NEIGHBOURHOOD 
*** DELINQUENCY AND VICTIMIZATION
*** POLICE CONTACT
*** EXPERIENCES WITH THE POLICE 
*** SAMPLE SELECTION

*run after recordings of French variables are concluded

******************************** GENERAL ********************************

*Drop Berufssch�ler
drop if xtyp==8

label var kid "num. questionnaire"

gen schlid = xids
lab var schlid "ID school"

gen country=0
lab var country "country"

lab define countrylb 1"France" 0"Germany", replace 
lab value country countrylb

recode xcity (1=3) (2=4), gen(city)
lab var city "city"
lab define citylb 1"Grenoble" 2"Lyon" 3"Cologne" 4 "Mannheim", replace 
label value city citylb

label define dummylb 0 "no" 1 "yes" 

******************************** INDIVIDUAL DEMOGRAPHICS ********************************
*** sex
gen sex= a1
lab define sexlb 0"boys" 1"girls"
label var sex "sex"
lab val sex sexlb
fre sex

**** age 
*note : generate age4 (age categorical)
* difference between age2 and age3?

gen age1=a2ager

label variable age1 "age continuous"

*replace age1=18 if a2ager>= 19 
*label var age1 "age continuous - cut after 18"

gen age2 = round(a2ager)
recode age2 (min/12=12) (18/max=18) 
lab var age2 "age continuos- recoded"
lab define age2lb 12"up to 12" 18"18+"
label val age2 age2lb

recode age2 (12/13=13) (17/18=17), gen (age3)
lab define age3lb 13"12-13" 17"17-18"
label val age3 age3lb

gen age4 = a2ager
label variable age4 "age categorical"
replace age4 = 13 if a2ager <14
replace age4 = 14 if a2ager >= 14 & a2ager < 15
replace age4 = 15 if a2ager >= 15 & a2ager < 16
replace age4 = 16 if a2ager >= 16 & a2ager < 17
replace age4 = 17 if a2ager >=17 & a2ager < 18
replace age4 = 18 if a2ager >= 18

codebook  age1-age4

******** ******** ******** ******** ******** ******** 
** migration SEE MIGRATION DE DOFILE

* ethnicity (common dataset)
*** ETHN1 = migrant background if - (1) both partens born abroad OR (2) 3 or 4 grandparents born abroad
*** 1 parent born abroad OR up to 2 granparents born abroad = NO migration background

gen ethnic1 = ethn2DE
label var ethnic1 "ethnicity large 7 categories"
label define ethnic1lb 0 "native" 1 "Europe" 2 "Turkey(D)/Maghreb(F)" 3"Africa and Ex-Soviet(D)/Middle East(F)" 4"Asia and World" 5 "Mixed native and Turkey(D)/Maghreb(F)" 6"Mixed native and other" 99 "Missing", replace
lab val ethnic1 ethnic1lb
tab ethnic1

gen ethnic2= ethnic1
label var ethnic2 "ethnicity short 5 categories"
recode ethnic2 (2=1) (1=2) (3=2) (4=2) (5=3) (6=4) (99=.)
label define ethnic2lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB " 3 "Mixed native and Turkey(D)/Maghreb(F)" 4 "Mixed native and other", replace
label value ethnic2 ethnic2lb
tab ethnic2

gen ethnic3= ethnic2
label var ethnic3 "ethnicity short 3 categories - mixed as native"
recode ethnic3 (3/4=0) 
label define ethnic3lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB" , replace
label value ethnic3 ethnic3lb
tab ethnic3

gen ethnic4= ethnic2
label var ethnic4 "ethnicity short 3 categories- without mixed"
recode ethnic4 (3/4=.) 
label define ethnic4lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB" , replace
label value ethnic4 ethnic4lb
tab ethnic4

recode ethn1DE (0=0) (1=1) (2=3)(3=2)(4=3)(5=3)(6=4)(7/8=.) (99=.), gen(ethnic5)
lab var ethnic5 "ethnicity 4 cat. - by continents withouth mixed"
lab define ethnic5lb 0 "native" 1 "Europe" 2 "Africa" 3 "Asia, including Ex-Soviet and Turkey (D) and Middle East (F)" 4 "Rest of World"
lab value ethnic5 ethnic5lb

*ethnic group (german dataset only)
fre a4a a4f a4f2

recode a4f (5=4)(6=4)(8=9), gen(a4f3)
recode a4f3 (7=5) (9=6) (10=7) (11=8)
label variable a4f3 "ethnicity large - German definition"
label define a4f3lb 0 "Germany" 1 "Turkey" 2 "south EU" 3 "Russia" 4 "East EU" 5 "Muslim countiers" 6 "Other migrants" 7 "Mixed Germany/Turkey" 8 "Mixed Germany/Migrants"
label value a4f3 a4f3lb

/*label define a4f2lb 0 "german" 1 "turkey" 2 "russia/ex SU" 3 "other migrants" 4 "mixed german/migrants", replace
label value a4f2 a4f2lb*/

drop a4f2 // ???

recode a4f (10=11) (2=9) (4/8=9), gen (a4f2)
label variable a4f2 "ethnicity short - German definition"
label define a4f2lb 0"German" 1"Turkish" 3"Russia" 9"other migration background" 11"mixed German/migration background"
label value a4f2 a4f2lb

recode a4f2 (1/11=1), gen(a4f2d)
label variable a4f2d "ethnicity dummy - German definition" 
label value a4f2d dummylb
tab a4f2d

fre a4f2 
fre a4f3
fre a4f2

*ancestry
codebook a4d

label variable a4d "ancestry"
label define a4dlb 0 "both parents German, max. 2 grandparents non German" 1 "1 parent not German, grandparents non German" 2 "max 1 parent non German, min. 3 grandparetns non German" 3 "both parents non German"
label value a4d a4dlb

recode a4d (2=1) (3=2), gen(a4d2)
label define a4d2lb 0"both parents German" 1 "one parent born in a foreign country" 2 "both parents or at least 3 grand parents born in a foreign country", replace
label value a4d2 a4d2lb 

recode a4d  (1/3=1), gen (a4dd)
label variable a4dd "ancestry dummy"
label value a4dd dummylb

fre a4d a4d2 a4dd

*generation
gen generat1= generat1DE
label var generat1 "immigration generation - large"
label define generat1lb ///
0 "no immigration" ///
1 "kid foreign: immigrated >=5 yrs age or no information about age of immigration" ///
2 "kid foreign: immigrated < 5 yrs age" ///
3 "kid native: parents foreign, less than two gp native" ///
4 "kid native: parents foreign, two or more gp native" ///
5 "kid native: one parent native, less than two gp native" ///
6 "kid native: one parent native, two gp native" ///
7 "kid native: two parents native, less than two gp native" ///
8 "kid native: two parents native, two gp native" ///
99 "missing", replace
label value generat1 generat1lb

gen generat2= generat2DE
label var generat2 "immigration generation - short mixed separate"
label define generat2lb ///
0 "no immigration" ///
1 "1. generation, kid immigrated >=5 yrs age or no information about age of immigration" ///
2 "1. generation, kid immigrated < 5 yrs age" ///
3 "2. generation" ///
4 "3. generation" ///
5 "1 parent foreign + 2 gp foreign, 1 parent native + 2 gp native" ///
99 "missing", replace
label value generat2 generat2lb

gen generat3= generat3DE
label var generat3 "immigration generation - short mixed 2. generation"
label define generat3lb ///
0 "no immigration" ///
1 "1. generation, kid immigrated >=5 yrs age or no information about age of immigration" ///
2 "1. generation, kid immigrated < 5 yrs age" ///
3 "2. generation" ///
4 "3. generation" ///
99 "missing", replace
label value generat3 generat3lb


******** ******** ******** ******** ******** ******** 
*** national identiy
* drop fre a8nr_b a8nr_c

gen natident1 = a8nr
recode natident1 (.= 99)
replace natident1=1 if ethnic1==0 & natident1==99
lab var natident1 "identity as native or group of origin - large" 
label define natident1lb 1"completely FR/GE" 2"more FR/GE" 3"devided" 4"more group of origin" 5"completely group of origin" 99 "missing", replace
label val natident1 natident1lb

recode natident1 (1/2=1) (3=2) (4/5=3) , gen (natident2)
replace natident2=1 if ethnic1==0 & natident2==99
lab var natident2 "identity as native or group of origin - short" 
lab  define natident2lb 1"host country" 2"divided" 3"country of origin" 99 "missing", replace
label val natident2 natident2lb

fre natident1 natident2

*** citizenship as adult	
fre a9 a4d

gen citizen = a9
replace citizen=. if ethn1DE==0 
label variable citizen "decision for citizenship"
label define citizenlb 1"only host country" 2 "only country of origin" 3 "both citizenships"
label value citizen citizenlb

tab citizen a4d

******** ******** ******** ******** ******** ********
** religion
fre m2

gen relig1= m2
recode relig1 (1=4) (2=3) (3=2) (4=1) (.=99)

label var relig1 "importance of religion"
label define relig1lb 1 "not important at all"  2 "fairily important" 3 "important" 4  "very important" 99 "missing", replace 
label value relig1 relig1lb

recode relig1 (1/2=0) (3/4=1), gen(relig2)
label var relig2 "importance of religion- dummy"
label define relig2lb 0"not important" 1 "important" 99 "missing", replace 
label value relig2 relig2lb

fre relig1 relig2

******************************** FAMILY ENVIRONMENT ********************************
***family disadvantage, parental attachment, parental monitoring?
fre f4a f6m_2 ISEIhigh 

*** education 
*Hauptabschluss=no degree???

fre f4a

*recode f4a (.=0)(2/3=2)(4=3)(5=4), gen (educ1)
recode f4a (.=0)(1/2=1)(3=2)(4=3)(5=4), gen (educ1)
lab var educ1 "highest education of mother/father"
lab define educ1lb  0"don't know/NA" 1"no degree" 2"degree below bac/Abi" 3"Bac/Abi" 4"above Bac/Abi" ,replace
label value educ1 educ1lb
fre educ1

recode educ1 (4=1) (0/3=0), gen (educ2)
lab var educ2 "highest education of mother/father dichot."
lab define educ2lb  0"else/don't know/NA" 1"Above Bac/Abi" , replace
label value educ2 educ2lb

gen f4a_a = f4a
label variable f4a_a "parental education large - only Germany" 
replace f4a_a=. if f4a==0
label define f4a_alb 1 "not graduated" 2 "Hauptabschluss" 3 "Mittlere reife/POS" 4 "Abitur/EOS" 5 "academic studies"
label value f4a_a f4a_alb

gen f4a_b = f4a
label variable f4a_b "parental education short - only Germany" 
recode f4a_b (3=2) (4=2) (5=3)
label define f4a_blb 0 "dont't know" 1 "not graduated" 2 "graduated" 3 "academic studies", replace 
label value f4a_b f4a_blb

fre educ1 educ2
fre f4a_a f4a_b


*** unemployment
**TO DO: correct f5_9m and f5_9v
***** dole_m/dole_p:  for mother/father separately
* yes: now or past unemployed
* no: both employed
* don�t know: both don�t know or one don�t know and one employed

***** dole1/dole2 : one/both parents, plus combinations of don't know/no answer
fre f5_3m f6m f5_8m f5_9m

*recode f5 variable
foreach v of var f5_1m - f5_9m {
	gen `v'r= `v'
}

foreach v of var f5_1v - f5_9v {
	gen `v'r= `v'
}

*replace f5_9mr="ARBEITSLOS" if f5_9m=="ARBEITET NICHT" | f5_9m=="F�HRER EINER FIRMA" | f5_9m =="HAT VOR MEINER GEBURT ALS VORSTANDSSE.." | f5_9m=="NICHTS" | f5_9m=="Nix" | f5_9m=="VERTRAG ABGELAUFEN"
*replace f5_3mr =1 if  f5_9mr=="ARBEITSLOS" 
*replace f5_9mr="" if f5_9mr=="ARBEITSLOS"

*replace f5_9vr="ARBEITSLOS" if f5_9v=="DROGEN ANPFLANZEN" | f5_9v=="FC BAYERN M�NCHEN FAN" | f5_9v=="NICHTS" 
*replace f5_9vr="WEISS NICHT" if f5_9v=="-" | f5_9v=="----" | f5_9v=="--------" | f5_9v=="----------" | f5_9v=="--.----" | f5_9v==".-" | ///
*	f5_9v=="KEINE AHNUNG" | f5_9v=="KEINEN KONTAKT" | f5_9v=="ONKEL" | f5_9v=="WEI� ICH NICHT"
*replace f5_9vr="" if f5_9vr=="ARBEITSLOS" | f5_9vr=="WEISS NICHT"

replace f5_8mr=0 if f5_9mr !=""
replace f5_8vr=0 if f5_9vr !=""

egen f5m= anycount (f5_1mr - f5_8mr), values (1)
egen f5v= anycount (f5_1vr - f5_8vr), values (1)
fre f5m f5v

replace f5m=1 if f5_9m!=""
replace f5v=1 if f5_9v!=""

replace f5_8mr=0 if  f5m==2
replace f5_8vr=0 if  f5v==2

replace f5_8mr=1 if f5m>2
replace f5_8vr=1 if f5v>2

foreach v of var f5_1mr - f5_7mr {
	replace `v'=0 if f5_8mr==1
}

foreach v of var f5_1vr - f5_7vr {
	replace `v'=0 if f5_8vr==1
}

egen f5mr= anycount (f5_1mr - f5_8mr), values (1)
egen f5vr= anycount (f5_1vr - f5_8vr), values (1)

egen f5m_mis= anycount (f5_1mr - f5_8mr), values (0)
egen f5v_mis= anycount (f5_1vr - f5_8vr), values (0)

gen dole_m=-1
replace dole_m = 1 if  f5_3mr == 1 | f6m == 1 
replace dole_m=0 if dole_m==-1 & f5_3mr == 0 & f6m==0 & f5_8mr==0  
replace dole_m=2 if dole_m==-1 & f5_3mr == 0 & f5_8mr == 1 
replace dole_m =2 if dole_m==-1 & f5_3mr == 0 & f5_8mr == 0 & (f6m ==9 | f6m==.) 
lab var dole_m "mother unemployed (now or last year)"
lab define dole_mlb 0"no" 1"yes" 2"don't know/no answ./sysmis"
label value dole_m dole_mlb

gen dole_p=-1
replace dole_p = 1 if  f5_3vr == 1 | f6v == 1 
replace dole_p=0 if dole_p==-1 & f5_3vr == 0 & f6v==0 & f5_8vr==0  
replace dole_p=2 if dole_p==-1 & f5_3vr == 0 & f5_8vr == 1 
replace dole_p = 2 if  dole_p==-1 & f5_3vr == 0 & f5_8vr == 0 & (f6v ==9 |f6v==.) 
lab var dole_p "father unemployed (now or last year)"
lab define dole_plb 0"no" 1"yes" 2"don't know/no answ./sysmis"
label value dole_p dole_plb

gen dole1=-1
replace dole1=0 if dole_p == 0 & dole_m == 0
replace dole1=0 if (dole_p ==2 & dole_m == 0 )| (dole_p == 0 & dole_m == 2)
replace dole1=1 if (dole_p == 1 & dole_m == 0) | (dole_p == 0 & dole_m == 1)
replace dole1=2 if (dole_p == 1 & dole_m == 2) | (dole_p == 2 & dole_m == 1)
replace dole1=2 if dole_p == 2 & dole_m == 2
replace dole1=3 if dole_p == 1 & dole_m == 1
lab var dole1 "unemployed parents"
lab define dole1lb 0"moth. and fath. employed or one employed and one unclear" 1"moth. or fath. unemployed (other employed)" 2"moth. or fath. unemployed (other unclear) or both unclear" 3"both unemployed" , replace
label value dole1 dole1lb

gen dole2 = 0
replace dole2=1 if dole_m == 1 | dole_p == 1
replace dole2=2 if dole_m == 2 & dole_p== 2
lab var dole2 "mother or father unemployed"
lab define dole2lb 0"no" 1"yes" 2"unclear"
lab val dole2 dole2lb

fre dole_m dole_p dole1 dole2

* welfare recipient
label variable f6m_2 "Hartz-IV"
label define f6m_2lb 0 "no" 1 "yes" 9 "don't know" , replace 
label value f6m_2 f6m_2lb

fre f6m_2

*social status CORR
*until 50 % = modest status, between 50% - 75 % = intermediate stats, highest 25% = higher status
*(see also distribution social status in  french data
label variable ISEIhigh "socio-economic status family (ISEI) - highest score out of both parents"

fre isco08m1 isco08v1

/*
0 Streitkraefte 
1 Fuehrungskraefte 
2 Akademische Berufe 
3 Technikerinnen  
4 Buerokraefte 
5 Verkaeuferinnen 
6 Forstwirtschaft und Fischerei 
7 Handwerk 
8 Maschinen- und Montageberufe  
9 Hilfsarbeitskraefte 
*/

recode isco08m1 (0=1) (1=1) (2=1) (3=1) (6=1)  (4=2) (5=2) (7=2) (8=2) (9=2), gen (R3isco08m) 
recode isco08v1 (0=1) (1=1) (2=1) (3=1) (6=1)  (4=2) (5=2) (7=2) (8=2) (9=2), gen (R3isco08v)  

gen ISCOhigh=.

replace ISCOhigh=1 if R3isco08m==1 | R3isco08v==1
replace ISCOhigh=2 if R3isco08m==2 & R3isco08v==2
replace ISCOhigh=2 if (R3isco08m==2 & R3isco08v==.) | (R3isco08m==. & R3isco08v==2)

fre ISCOhigh
spearman ISCOhigh dole2
tab ISCOhigh dole2, column row nokey chi2 lrchi2 V

gen status=ISCOhigh
label var status "social status family"
label define statuslb 2 "modest/intermediate" 1 "higher" , replace
label value status statuslb
fre status

******** ******** ******** ******** ******** ******** 
*family setting 
fre f1_4_1 f3a f3b

label variable f3a "family setting"
label define f3alb 0 "two bio. parents" 1 "1 bio. parent one family household" 2 "1 bio. parent one stepparent" 3 "no parents"
label value f3a f3alb
recode f3a (-1=.)

gen famsetd= f3b
recode famsetd (.=99) 
recode famsetd (99=1)
lab var famsetd "family setting - dichotom"
lab define famsetdlb 0 "complete" 1 "not complete or missing" 
lab value famsetd famsetdlb

fre f3a famsetd

*completeness family
label variable f1_4_1 "complete family"
label value f1_4_1 dummylb

fre f1_4_1

*language spoken at home
label variable a7mv "language spoken with father/mother"
label define a7mvlb 0 "with both german" 1 "with father or mother ohter than german" 2 "with both ohter than german", replace
label value a7mv a7mvlb

fre a7mv

******** ******** ******** ******** ******** ******** 
*Attachment to mother
fre se2ma 

label variable se2ma "positive attachment to mother"
label define se2malb 1 "not true at all" 4 "completely true", replace
label value se2ma se2malb

fre se2ma 

gen attmtr1 = e2_1m 
gen attmtr2 = e2_2m 
gen attmtr3 = e2_3m 
gen attmtr4 = e2_4m 
gen attmtr5 = e2_5m 
gen attmtr6 = e2_6m 

lab var attmtr1 "I trust my mother deeply -only D"
lab var attmtr2 "I tell everything about me and what I am doing to my mother -only D"
lab var attmtr3 "My mother constantely blames me -only D"
lab var attmtr4 "I often have a dispute with my mother -only D"
lab var attmtr5 "my mother cares about me and what I am doing -only D"
lab var attmtr6 "It happens that my mother beats me or throws something against me -only D"

lab define attmtrlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
label value attmtr1-attmtr6 attmtrlb

foreach v of var attmtr1-attmtr6 {
	tab `v', m
}

foreach v of var attmtr1 attmtr2 attmtr5 {
	recode `v' (4=1) (3=2) (2=3) (1=4), gen(`v'f)
}

*Attachment to father 
* poly scales  !!!
fre se2va se2b se2c se2ck

label variable se2va "positive attachment to father"
label value se2va se2malb

*Disputes/violence with mother/father
* poly scales  !!!
label variable se2b "dispute with mother / father"
label value se2b se2malb

label variable se2c "violence of mother / father"
label value se2c se2malb

fre se2ck, nol

label variable se2ck "violence of mother / father - categorical"
label define se2cklb 0 "no violence" 1 "average violence" 2 "strong violence"
label value se2ck se2cklb

*parental monitoring
* poly scales  !!!
fre se1
label var se1 "positive parental monitoring"

gen parmon1 = e1_1 
gen parmon2 = e1_2 
gen parmon3 = e1_3 

lab var parmon1 "my parents know with whom I spend my free time"
lab var parmon2 "my parents know what I do during my free time "
lab var parmon3 "my parents know my friends well"

lab define parmonlb 1"never" 2 "sometimes" 3"often" 4"almost always"
label value parmon1-parmon3 parmonlb

*mean scale dependend variable instead of factor variable for joint dataset
capture drop sparmon
egen sparmon=rowmean(parmon1 parmon2)

lab var sparmon "mean parental monitoring (higher=closer monitoring)"


******************************** SOCIAL ENVIRONMENT ********************************
*attitudes to school 
* poly scales  !!!
fre ss9 ss9a
label variable ss9a "positive school attitude"

gen attsch1 = s9_1
gen attsch2 = s9_2 
gen attsch3 = s9_3 
gen attsch4 = s9_4 

lab var  attsch1 "I like my school a lot " 
lab var  attsch2 "I am interested in what I am learning at school " 
lab var  attsch3 "I apply myself in school " 
lab var  attsch4 "I study with friends for the school (outside the regular school time)"

lab define attschlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
label value attsch1-attsch4 attschlb

*school performance

*middle school marks

*school grade
recode xgrade (21=.) (22=.), gen(xgrade_a)
label variable xgrade_a "school grade - short"
label define xgrade_alb 8 "grade 8" 9"grade 9" 10 "grade 10"
label value xgrade_a xgrade_alb

fre xgrade_a

***school type
fre xtypdet
recode xtypdet (8=.) (7=5), gen(xtypdet_a)
label variable xtypdet_a "school form in detail - without BBRS"
label define xtypdet_alb 1 "Gymnasium" 2 "Gesamtschule" 3 "Realschule" 4 "Hauptschule" 5 "Waldorfschule"
label value xtypdet_a xtypdet_alb

recode xtypdet (7=1) (2/4=0) (8=0), gen(xtypdetd1)
label variable xtypdetd1 "Gymnasium/Waldorfschule"
label value xtypdetd1 dummylb

fre xtypdet_a
fre xtypdetd1

*school mark
label variable s6_1 "german language mark"
fre s6_1

*German communication skills: already defined (s6_1)
fre s6_1 ss6

******** ******** ******** ******** ******** ******** 
*friends with migration background CORR
fre p4

recode p4 (1=5) (2=4) (4=2) (5=1), gen(mbfriendc)

lab var mbfriendc "friends with migration background"
lab define mbfriendclb 1 "none" 2 "less than half" 3 "half" 4 "more than half" 5 "all"
label value mbfriendc mbfriendclb

recode mbfriendc (5=0)(4=1)(3=1)(2=1), gen(mbfriend)
recode mbfriend (.=99)
lab var mbfriend "friends without migration background - dummy"
lab define mbfriendlb 0"no" 1"yes" 99 "missing", replace
label value mbfriend mbfriendlb

fre mbfriendc mbfriend

*leisure time activities (school/athletic activities) - MISSING IN FR!!
*poly scales !!!

fre sp10a sp10b sp10c

label variable sp10a "fun / action activities"
label define sp10alb 1"never" 4 "very often"
label value sp10a sp10alb

label variable sp10b "cultural activities / youth association"
label value sp10b sp10alb

label variable sp10c "sport activities"
label value sp10c sp10alb

gen activ1 = p10_1 
gen activ2 = p10_2 
gen activ3 = p10_3 
gen activ4 = p10_4 
gen activ5 = p10_5 
gen activ6 = p10_6 
gen activ7 = p10_7 
gen activ8 = p10_8 
gen activ9 = p10_9 
gen activ10 = p10_10 
gen activ11 = p10_11 
gen activ12 = p10_12 

lab var activ1 "play music instrument"
lab var activ2 "read bookds"
lab var activ3 "go to the youth center"
lab var activ4 "sport without association"
lab var activ5 "train/practicing sport actively"
lab var activ6 "youth group/cours with appointed dates"
lab var activ7 "undertaking activities with family members"
lab var activ8 "meet friends and hang out on the street/on a square"
lab var activ9 "go to clubs, parties"
lab var activ10 "meet friends and hang out in the evening in a park or close to the see and drink"
lab var activ11 "go to pubs"
lab var activ12 "theater performance, classical concerts, museums "

foreach v of var activ* {
	label define activlb 1"never" 2"sometimes" 3 "often" 4 "very often", replace
	label value `v' activlb
	tab `v'
}

* night out with friends
fre p6 p7n p7k

gen nights1 = p6-1
recode nights1 (99=99)
lab var nights1 "Nights out with friends (FR: after 18 h/DE: afternoon or evening)"
lab define  nights1lb 0"none" 1"once"  2"twice" 3"3-4 times" 4"5+ times" 99 "missing"
label value nights1 nights1lb

gen nights2 = p7k
recode nights2 (-9 99=99)
lab var nights2 "Nights out with friends (F: how many/G:how long?)"
lab define nights2lb  0"none" 1"FR: 1 DE: 20h" 2"FR: 2 DE: 21h" 3"FR: 3-4 DE: 22h"  4"FR: 5+ DE: after 22h"  99 "missing" 
label value nights2 nights2lb

recode p7k (1=0) (2/4=1), gen (p7kd)
label define p7kdlb 0"never/until 8pm" 1"after 8pm"
label value p7kd p7kdlb 

* time back home
gen street = p10_8-1
recode street (.=99) 
lab var street "being out on the street"
lab define streetlb 0"never" 1 "rarely" 2"often" 3"very often" 99 "missing" 
label value street streetlb

*alcohol
fre d4_11ev p13 

label variable p13 "alcohol"
label define p13lb 1"never" 2"once" 3"2-5 times" 4 "6-10 times" 5"more than 10 times"
label value p13 p13l

fre p13k
gen drunk = p13k -1 
recode drunk (.=99)
lab define drunklb 0"never" 1"once" 2"2-5 times" 3"6+ times" 99 "missing" 
lab var drunk "ever been drunk (lifetime)"
lab val drunk drunklb

fre nights1 nights2
fre drunk street

******************************** NEIGHBOURHOOD ********************************
	
***residential mobility / lenht of residence 
fre f10 f11_1 f11_2

****opinions of local area 
* poly scales  !!!
fre sq1a sq2a sq12a
label variable sq1a "risks of neighbourhood for youth"
label define sq1alb 1 "small" 4 "high"
label value sq1a sq1alb

label variable sq2a "disorder/violence/durgs in neighbourhood"
label value sq2a sq1alb

label variable sq12a "neighbourhood disorder/risks"
label value sq12a sq1alb

fre q1_1 - q2_3
*recode q1_1 (4=1) (3=2) (2=3) (1=4), gen (q1_1f)
*recode q1_3 (4=1) (3=2) (2=3) (1=4), gen (q1_3f)

gen nbhd1= q1_1f
gen nbhd2= q1_2
gen nbhd3= q1_3f
gen nbhd4= q2_1
gen nbhd5= q2_2
gen nbhd6= q2_3

corr nbhd1 nbhd2 nbhd3 nbhd4 nbhd5 nbhd6

label var nbhd1 "feels well in neighbourhood"  
label var nbhd2 "good nbhd for children to grow up" 
label var nbhd3 "youths become delinquent" 
label var nbhd4 "incivil: litter on street" 
label var nbhd5 "incivil: drugs" 
label var nbhd6 "incivil: violence"  

foreach v of var nbhd1 nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 {
	recode `v' (.=99)
}

lab define nbhd13lb 1"not true at all" 2"not true" 3"true" 4"completely true" 99 "missing"
lab define nbhd46lb 1"never" 2"rarely" 3"often" 4"very often" 99 "missing"

label value nbhd1-nbhd3 nbhd13lb
label value nbhd4-nbhd6 nbhd46lb


foreach v of var nbhd* {
	tab `v', m
}

****quality of life 	
*personal satisfaction with life
fre a10

label variable a10 "happiness in life at the moment"

******************************** DELINQUENCY AND VICTIMIZATION ********************************
*self-control - GERMANY ONLY
* poly scale !!!
fre sm1	

label variable sm1 "low self-control"
label define sm1lb 1 "not true at all" 4 "very true"
label value sm1 sm1lb

*attitudes favorable to delinquency
* poly scale !!!
fre sd8a sd8b
label variable sd8a "violence / threshold for braking norms" 
label variable sd8b "tolerance of violence"

gen attviol1 = d8_1 
gen attviol2 = d8_2 
gen attviol3 = d8_3 
gen attviol4 = d8_4 
gen attviol5 = d8_5 

lab var attviol1 "it is normal to beat somebody if one has been provoked"
lab var attviol2 "every dispute can be settled through talks"
lab var attviol3 "some conflicts can only be solved by violent means"
lab var attviol4 "one has to respect the law, even if the own interests are overlooked"
lab var attviol5 "one can do something forbidden if he/she is not caught"

lab define attviollb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
label value attviol1-attviol5 attviollb

fre d5bd12 d5cd12 d5ank d5bnk

label define d5lb 0 "none" 1 "once" 2 "2-5 times" 3 "6-10 times" 4 "more than 10 times" 
label define d5lb2 0 "none" 1 "once" 2 "twice" 3 "more 3 times"
label define d5lb2b 0 "none" 1 "once" 2 "twice" 3 "3 times"
label define d5lb3 0 "none" 1 "once" 2 "twice" 

******** ******** ******** ******** ******** ********  
** victimization joint DE FR dataset
gen vic1 = d5_1yss          
gen vic2 = d5_2yss          
gen vic3 = d5_3yss          
gen vic4a = d5_4yss          
gen vic4b = d5_5yss    

gen vic4 = vic4a + vic4b

lab var vic1 "theft" 
lab var vic2 "blackmail" 
lab var vic3 "assault" 
lab var vic4 "cyberbullying" 

foreach var in vic1-vic4 {
	recode `var' (50/max=50)
	recode `var' (.=99)
	*recode `var' (.b=99)
	fre `var'
}

egen vicmiss = anycount(vic1 vic2 vic3 vic4), values (99)

forvalues i=1/4 {
	replace vic`i'= 0 if vic`i'==99 & vicmiss <4
	recode vic`i' (99=.)
}

fre vic1 vic2 vic3 vic4

egen vic_sum= rowtotal(vic1 vic2 vic3 vic4), missing 
label var vic_sum "victimization - incid."

recode vic_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(vic_k)
lab var vic_k "victimization - cat."
label define vic_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
lab value vic_k vic_klb

recode vic_k (1/2=1) (3=2) (4/5=3), gen(vic_k2)
lab var vic_k2 "victimization - cat. short"
label define vic_k2lb 0 "0" 1 "1-2" 2 "3-5" 3 ">5", replace
label value vic_k2 vic_k2lb

*SRV overall 
fre d5av // SRV Gesamt Viktimisierung - prevalence
fre d5an // Inzidenz Gesamt-VICT
fre d5ank // SRV Inzidenz Gesamt-Viktimisierung - categorical 
fre d5ad // Inzidenz Gesamt-VICT dummy
label variable d5av "SRV overall prevalence"
recode d5av (3/5=3), gen(d5avk)
label variable d5avk "SRV overall prevalence - categorical"
label value d5avk d5lb2
label variable d5ank "SRV overall incidence - categorical"
label value d5ank d5lb
label variable d5an "SRV overall incidence"
label variable d5ad "SRV overall - dummy"
label value d5ad dummylb

fre d5bnk // SRV Inzidenz ohne Cyberbulling
fre d5bn //SRV Inzidenz Gewalt-VICT (ohne CB)
fre d5bv // SRV ohne Cyberbulling- prevalence categorical
fre d5bd // SRV ohne Cyberbulling- prevalence dummy
label variable d5bnk "SRV incidence - without cyberbulling - categorical"
label value d5bnk d5lb3
label variable d5bn "SRV incidence - without cyberbulling"
label variable d5bv "SRV prevalence - without cyberbulling "
gen d5bvk = d5bv
label variable d5bvk "SRV prevalence - without cyberbulling  - categorical"
label value d5bvk d5lb2b
label variable d5bd "SRV without cyberbulling - dummy"
label value d5bd dummylb

fre d5cnk // Inzidenz Cyberbulling Viktimisierung 
fre d5cn // SRV Inzidenz CB-VICT
fre d5cv // SRV Cyberbulling Viktimisierung - prevalence categorical
label variable d5cn "SRV incidence cyberbulling" 
label variable d5cnk "SRV incidence cyberbulling - categorical"
label value d5cnk d5lb
label variable d5cv "SRV  prevalence cyberbulling"
gen d5cvk = d5cv
label variable d5cvk "SRV  prevalence cyberbulling - categorical"
label value d5cvk d5lb3
label variable d5cd "SRV cyberbulling - dummy"
label value d5cd dummylb

*d4b2polv

******** ******** ******** ******** ******** ********  
**SRD joint DE FR dataset
gen srd1 = d4_3yss
gen srd2 = d4_6yss
gen srd3 = d4_8yss
gen srd4 = d4_10yss
gen srd5 = d4_11yss
gen srd6 =  d4_12yss
gen srd7 = d4_13yss

lab var srd1 "vandalism" 
lab var srd2 "vehicle theft" 
lab var srd3 "shoplifting" 
lab var srd4 "break in" 
lab var srd5 "use drugs" 
lab var srd6 "sell drugs" 
lab var srd7 "assault"

foreach var in srd1-srd7 {
	recode `var' (50/max=50)
	recode `var' (.=99)
	*recode `var' (.b=99)
	fre `var'
}

egen srdmiss = anycount(srd1 srd2 srd3 srd4 srd5 srd6 srd7), values (99)
fre srdmiss

forvalues i=1/7 {
	replace srd`i'= 0 if srd`i'==99 & srdmiss <7
	recode srd`i' (99=.)
}

egen srd_sum= rowtotal(srd1 srd2 srd3 srd4 srd5 srd6 srd7), missing 
label var srd_sum "numb. self reported delinquency - incid."

recode srd_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(srd_k)
lab var srd_k "self reported delinquency - cat."
label define srd_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
lab value srd_k srd_klb

recode srd_k (1/2=1) (3=2) (4/5=3), gen(srd_k2)
lab var srd_k2 "self reported delinquency - cat. short"
label define srd_k2lb 0 "0" 1 "1-2" 2 "3-5" 3 ">5", replace
label value srd_k2 srd_k2lb 

recode d4b2nr (1/2=1) (3/5=2) (6/max=3), gen(srd_k2DE)
label value srd_k2DE srd_k2lb 

/* ev=ever
ys=year self
yp=polizei hat davon erfahren
nr= count(Inzidenz)
k=kategorial
d=dummy

*/


fre d4av d4av12 d4bv12 d4b2v
fre d4bd d4b2d d4bd12 d4b2d12 

label define d4lb 0 "none" 1 "once" 2 "twice" 3 "3-5 times" 4 "more than 5 times"
label define d4lb2 0 "none" 1 "once" 2 "twice" 3 "3 times"
label define d4lb3 0 "none" 1 "once" 2 "twice" 
label define d4lb4 0 "none" 1 "once" 2 "2-3" 3 "4-6" 4 "7-10" 5 "11-15" 6 "16-20" 7 "21-30" 8 "more than 30"
label define d4lb5 0 "none" 1 "once" 2 "2-3" 3 "4-6" 4 "7-10" 5 "more than 10" 

*SRD overall
fre d4av // SRD gesamt - prevalence
fre d4av12 // SRD letzte 12 Mt. - prevalence
fre d4an // SRD gesamt, Del. count

label variable d4av "SRD overall prevalence"

recode d4av (3/5=3)(6/17=4), gen(d4avk)
label variable d4avk "SRD overall prevalence - categorical"
label value d4avk d4lb

recode d4av (1/17=1), gen (d4avd)
label variable d4avk "SRD overall prevalence - dummy"
label value d4avd dummylb

label variable d4an "SRD overall incidence"

*SRD without substance use/cyberbulling/pirated
fre d4bv // SRD ohne Raubkopie/Substanzkonsum/Cyberbulling - prevalence
fre d4bn // SRD 12M Gesamt count ohne Raubkop/Subst.konsum/Cyberbullying
fre d4bnr // SRD 12M Gesamt count ohne Raubkop/Subs. Konsum/Cyberbullying - cut after 25
*fre d4bnr2 // SRD 12M Gesamt count ohne Raubkop/Subst.Konsum/Cyberbullying - categorical
fre d4bnk // [Kat]SRD 12M Gesamt count ohne Raubkop/Cyberbullying/Substanzkonsum - categorical
fre d4bd // SRD ohne Raubkopie/Substanzkonsum/Cyberbulling - prevalence - dummy

label variable d4bv "SRD  prevalence - without substance use/cyberbulling/pirated"

recode d4bv (3/5=3)(6/13=4), gen(d4bvk)
label variable d4bvk "SRD  prevalence - without substance use/cyberbulling/pirated - categorical"
label value d4bvk d4lb

label variable d4bn "SRD  incidence - without substance use/cyberbulling/pirated"
label variable d4bnr "SRD  incidence - without substance use/cyberbulling/pirated - short"
label variable d4bnk "SRD  prevalence - without substance use/cyberbulling/pirated - categorical"
label value d4bnk d4lb4
label variable d4bd "SRD  prevalence - without substance use/cyberbulling/pirated - dummy"
label value d4bd dummylb

*SRD without cyberbulling/pirated
fre d4b2v // SRD ohne Cyberbulling/Raubkopie -prevalence
fre d4b2n // SRD 12M Gesamt count ohne Raubkop/Cyberbullying
fre d4b2nr // SRD 12M Gesamt count ohne Raubkop/Cyberbullying - cut after 25
*fre d4b2nr2 // SRD 12M Gesamt count ohne Raubkop/Cyberbullying
fre d4b2nk // Kat]SRD 12M Gesamt count ohne Raubkop/Cyberbullying - categorical

label variable d4b2v "SRD prevalence - without cyberbulling/pirated"
recode d4b2v (3/5=3)(6/14=4), gen(d4b2vk)
label variable d4b2vk "SRD prevalence - without cyberbulling/pirated - categorical"
label value d4b2vk d4lb
label variable d4b2n "SRD incidence - without cyberbulling/pirated"
label variable d4b2nr "SRD incidence - without cyberbulling/pirated - short"
label variable d4b2nk "SRD incidence - without cyberbulling/pirated - categorical"
label value d4b2nk d4lb4 
label variable d4b2d "SRD  prevalence - without cyberbulling/pirated - dummy"
label value d4b2d dummylb

recode d4b2nk (6/8=5), gen(d4b2nk_b)
label variable d4b2nk_b "SRD incidence - without cyberbulling/pirated - categorical short"
label value d4b2nk_b d4lb5



*SRD serious delinquency
fre d4cv // SRD schwere delinquenz prevalence
fre d4cn // SRD 12M schwere Del. count

recode d4cv (3/5=3)(6/7=4), gen(d4cvk)
label variable d4cvk "SRD prevalence - serious delinquency - categorical"
label value d4cvk d4lb
label variable d4cn "SRD incidence - serious delinquency"

*SRD serious property offence
fre d4dv // SRD schwere Eigentumsdelinquenz - prevalence
fre d4dn // SRD schwere Eigentumsdel., Counts 12M
gen d4dvk = d4dv
label variable d4dvk "SRD prevalence - serious property offence - categorical"
label value d4dvk d4lb2
label variable d4dn "SRD incidence - serious property offence"

*SRD violence
fre d4ev // SRD Gewalt - prevalence
fre d4en // SRD Gewalt, Counts 12M
gen d4evk = d4dv
label variable d4evk "SRD prevalence - violence - categorical"
label value d4evk d4lb2
label variable d4en "SRD incidence - violence"

*SRD cyberbulling

fre d4fv // SRD Cyberbulling - prevalence
fre d4fn // SRD Cyberbullying, Counts 12M
gen d4fvk = d4fv
label variable d4fvk "SRD prevalence - cyberbulling - categorical"
label value d4fvk d4lb3
label variable d4fn "SRD incidence - cyberbulling"

******** ******** ******** ******** ******** ******** 
*peer delinquency 
fre sd2a
label variable sd2a "delinquency in school - the higher the more"

gen peerdel1 = d2_1r-1
gen peerdel2 = d2_2r-1
gen peerdel3 = d2_3r-1
gen peerdel4 = d2_4r-1
gen peerdel5 = d2_5r-1
gen peerdel6 = d2_6r-1
gen peerdel7 = d2_7r-1
gen peerdel8 = d2_8r-1
gen peerdel9 = d2_9r-1

lab var peerdel1 "absenteeism"
lab var peerdel2 "volontarely damaged something"
lab var peerdel3 "shoplifting"
lab var peerdel4 "robbery"
lab var peerdel5 "violently stolen something from somebody"
lab var peerdel6 "injured somebody seriousely"
lab var peerdel7 "used drugs"
lab var peerdel8 "insulted somebody"
lab var peerdel9 "cyberbulling"


*foreach var in peerdel1-peerdel9 {
*	recode `var' (8=.)
*}

egen peerdel_sum=rowtotal(peerdel2 peerdel5 peerdel6 peerdel7), missing

label var peerdel_sum "delinquency of peers - versatility"

recode peerdel_sum (0=0) (1=1)(2/max=2), gen(peerdel_k)

lab var peerdel_k "delinquency of peers - cat."
label define  peerdellb  0 "none" 1 "one" 2 "several" 
label value peerdel_k peerdellb 

foreach var in peerdel1-peerdel9 {
	recode `var' (0=1)(1=2)(2=3)
}

*** polychoric scale instead of mean
*egen speerdelDE=rowmean(peerdel1-peerdel9)
*egen speerdel=rowmean(peerdel2 peerdel5 peerdel6 peerdel7)
*egen zspeerdel = std(speerdel) 

*Negative peer commitment
fre p14a p14ad sp15 sp15d

gen peergroup = p14a
recode peergroup (.=99)
label variable peergroup "peer group membership"
label define peergrouplb 0"not member" 1 "member in non violent peer group" ///
2 "member in violent peer group"
label value peergroup peergrouplb

gen peergroupd = p14ad
label variable peergroupd "violent peer group member - dummy"
label value peergroupd dummylb


******************************** POLICE CONTACT ********************************
***police contact overall
fre sc3as sc3bs sc3cs sc3ds
fre sc3ak sc3bk sc3ck sc3dk
fre sc3ad sc3bd sc3cd sc3dd

label define pcntklb 0 "none" 1 "once" 2 "twice" 3 "3-4 times" 4 "more than 4 times"
label define pcntdlb 0 "no" 1 "yes"

label variable sc3as "police contact 12 months incidence"
label variable sc3ak "police contact 12 months incidence - categorical"
label value sc3ak pcntklb 
label variable sc3ad "police contact 12 months incidence - dummy"
label value sc3ad pcntdlb 

fre c3_1_2r c3_2_2r c3_3_2r c3_4_2r c3_5_2r c3_6_2r c3_7_2r c3_8_2r

gen pcont1 = c3_1_2r
gen pcont2 = c3_2_2r
gen pcont3 = c3_3_2r
gen pcont4 = c3_4_2r
gen pcont5 = c3_5_2r
gen pcont6 = c3_6_2r
gen pcont7 = c3_7_2r
gen pcont8 = c3_8_2r

lab var pcont1 "As a witness or victim of a traffic offence/ accident" 
lab var pcont2 "As a witness of a criminal offence" 
lab var pcont3 "As a victim of a criminal offence"
lab var pcont4 "As a suspect of a criminal offence (e.g. shoplifting, brawl/fighting)" 
lab var pcont5 "As a traffic participant (e. g. on a bike ride)" 
lab var pcont6 "I was approached or checked (stopped and searched) on the street/ in a park/ on a public square"
lab var pcont7 "I talked to a police officer because I wanted to know something/ to get help"
lab var pcont8 "For other reasons"

fre pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8

foreach v of var pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8 {
	recode `v' (20/100 = 20) (101/max=-1), gen(`v'r)
	recode `v'r (-1 99=.)
	tab `v'r
}

foreach v of var pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8 {
	recode `v' (1/100=1) (101/max=-1), gen (`v'd)
	recode `v'd (-1 99=.)
	tab `v'd
}

egen pcont_sum= rowtotal(pcont1r pcont2r pcont3r pcont4r pcont5r pcont6r pcont7r pcont8r), missing

label var pcont_sum "number of police contacts last year - incid."

recode pcont_sum  (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcont_k)
recode pcont_sum  (0=0) (1/2=1) (3/5=2) (5/max=3), gen(pcont_k2)
recode pcont_sum  (0=0) (1/max=1), gen(pcont_d)

label var pcont_k "number of police contacts last year - cat."
label define pcont_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
label value pcont_k pcont_klb

label var pcont_k2 "number of police contacts last year - cat. short"
label define pcont_k2lb 0"0" 1"1-2" 2"3-5" 3">5"
label value pcont_k2 pcont_k2lb

label var pcont_d "police contact last year - dummy"
label value pcont_d dummylb

fre sc3as pcont_sum 
fre sc3ak pcont_k pcont_k2 
fre sc3ad pcont_d
 
******** ******** ******** ******** ******** ******** 
*** types of police contact
*** police contact victim/witness/self-initiated
label variable sc3ds "police contact victim/witness/self-initiated (1/2/3/7) 12 months incidence"	
label variable sc3dk "police contact victim/witness/self-initiated (1/2/3/7) 12 months incidence - categorical"	
label value sc3dk pcntklb
label variable sc3dd "police contact victim/witness/self-initiated (1/2/3/7) 12 months incidence - dummy"	
label value sc3dd pcntdlb

egen pconta_sum= rowtotal(pcont1r pcont2r pcont3r pcont7r), missing

label var pconta_sum "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - incid."

recode pconta_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pconta_k)
label var pconta_k "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - cat."
lab value pconta_k pcont_klb

recode pconta_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pconta_k2)
label var pconta_k2 "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - cat. short"
label value pconta_k2 pcont_k2lb

fre sc3ds pconta_sum 
fre sc3dk pconta_k pconta_k2 

recode pconta_k2 (1/3=1), gen(pcontad)

*police contact as crime/suspect 
recode pcont4r  (0=0) (1/2=1) (3/5=2) (6/max=3), gen(pcont4_k)
label var pcont4_k "number of police contacts as crime suspect last year (4) - cat."
lab val pcont4_k pcont_k2lb

fre pcont4_k

*** police contact control/suspicion
label variable sc3bs "police contact control/suspicion (4/5/6) 12 months incidence"
label variable sc3bk "police contact control/suspicion (4/5/6) 12 months incidence- categorical"
label value sc3bk pcntklb
label variable sc3bd "police contact control/suspicion (4/5/6) 12 months incidence- dummy"
label value sc3bd pcntdlb

egen pcontb_sum= rowtotal(pcont4r pcont5r pcont6r), missing
label var pcontb_sum "numb. pol.contacts last yr, suspicion/traffic control/stopped on street (4/5/6) - incid."

recode pcontb_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcontb_k)
recode pcontb_k (2.5=2)
lab var pcontb_k "numb. pol.contacts last yr, traffic suspicion/control/stopped on street (4/5/6) - cat."
lab value pcontb_k pcont_klb

recode pcontb_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pcontb_k2)
lab var pcontb_k2 "numb. pol.contacts last yr, suspicion/traffic control/stopped on street (4/5/6) - cat. short"
label value pcontb_k2 pcont_k2lb

recode pcontb_k2 (1/3=1), gen(pcontbd)


fre sc3bs pcontb_sum 
fre sc3bk pcontb_k pcontb_k2 

*** police contact control only
label variable sc3cs "police contact control (5/6) 12 months incidence "
label variable sc3ck "police contact control (5/6) 12 months incidence - categorical"
label value sc3ck pcntklb
label variable sc3cd "police contact control (5/6) 12 months incidence - dummy"
label value sc3cd pcntdlb

egen pcontc_sum= rowtotal(pcont5r pcont6r), missing

label var pcontc_sum "numb. pol.contacts last yr, traffic control/stopped on street (5/6)- incid."

recode pcontc_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcontc_k)
recode pcontc_k (2.5=2)

lab var pcontc_k "numb. pol.contacts last yr, traffic control/stopped on street (5/6) - cat."
lab value pcontc_k pcont_klb

recode pcontc_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pcontc_k2)
lab var pcontc_k2 "numb. pol.contacts last yr, traffic control/stopped on street (5/6) - cat. short"
label value pcontc_k2 pcont_k2lb

label value pcontc_k2 pcont_k2lb 

recode pcontc_k2 (1/3=1), gen(pcontcd)

fre sc3cs pcontc_sum
fre sc3ck pcontc_k pcontc_k2 

******** ******** ******** ******** ******** ******** 
*** last contact
fre c3last_filter 
fre c4c12_filter
fre c3c12_filter

recode c3last_filter (-99=99), gen (lastcont1)
lab var lastcont1 "filter for most recent contact with police"
label define lastcont1lb 99 "missing" 0 "no police contact" 1 "one type of police contact" 2 "several types police contacts", replace 
label value lastcont1 lastcont1lb
fre lastcont1

recode c4c12_filter (1/2=1) (-99=99), gen (lastcont2)
lab var lastcont2 "filter for validity of questions about last contact"
label define lastcont2lb  99"missing" 1"valid", replace
label value lastcont2 lastcont2lb
fre lastcont2

recode c3c12_filter (2=0) (4/5=1) (3=2) (1=3)(-99=99), gen(lastcont3)
lab var lastcont3 "FINAL FILTER for last contact"
label define lastcont3lb 99 "police contact missing + no valid information about contact" ///
0 "no police contact" ///
1 "filter valid: one type of police contacts" ///
2 "filter valid: several types of police contacts" ///
3 "filter not valid: one or more police contacts", replace 
label value lastcont3 lastcont3lb
fre  lastcont3

/*
label define lastcont3alb 99 "police contact missing + no valid information about contact" ///
0 "filter not valid: no police contact" ///
1 "filter not valid: one or more police contacts" ///
2 "filter valid: no police contact or contact missing" ///
3 "filter valid: several types of police contacts" ///
4 "filter valid: one type of police contacts", replace 
label value lastcont3a lastcont3alb
fre lastcont3a
*/

fre lastcont1 lastcont2 lastcont3

*review 
fre  lastcont1 lastcont2 lastcont3 if xmod==1
fre sc3ak sc3bk sc3dk c3_8_2r
tab c3_8_1r c3_8_2r, m
tab sc3bk if sc3av>1 & sc3dk==0 & c3_8_2r==0, m // 173 mehrmalige pol. Kontakte vom gleichen Typ
tab sc3dk if sc3av>1 & sc3bk==0 & c3_8_2r==0, m // 278 mehrmalige pol. Kontakte vom gleichen Typ

fre sc3ak
fre sc3ak if xmod==1
tab sc3ak lastcont1 if xmod==1, m
tab sc3ak lastcont3 if xmod==1, m

******************************** EXPERIENCES WITH THE POLICE ********************************
*** pleg (police legitimacy)
**poly scales !!!
fre c1_1 c1_2 c1_3 c1_4 c1_5 c1_6 c1_7 c1_8 

gen 	pleg1 = c1_1
gen 	pleg2 = c1_2
gen 	pleg3 = c1_3
gen 	pleg4 = c1_4
gen 	pleg5 = c1_5
gen 	pleg6 = c1_6
gen 	pleg7 = c1_7
gen 	pleg8 = c1_8

foreach v of var pleg* {
	recode `v' (4=1) (3=2) (2=3) (1=4)
}

lab var pleg1 "The police protect adolescents"
lab var pleg2 "The police disrespect adolescents"
lab var pleg3 "Overall the police can be trusted"
lab var pleg4 "One should in any case follow the instructions of the police"
lab var pleg5 "Even if having a serious problem, I would never contact the police"
lab var pleg6 "If adolescents protest violently and with riots against the police, I would join them"
lab var pleg7 "The police treat foreigners worse than native people"
lab var pleg8 "I could imagine becoming a police officer myself once"

lab define pleglb 1"don't agree at all" 2"don't agree" 3"agree" 4"completely agree"
lab value pleg1-pleg8 pleglb

fre  pleg1 pleg2 pleg3 pleg4 pleg5 pleg6 pleg7 pleg8


fre sc1a sc1b 

fre sc1a
label variable sc1a "positive attitude toward police"
label define sc1alb 1 "not true at all" 4 "very true"
label value sc1a sc1alb

recode sc1a (1/2.5=0) (2.51/4=1), gen (sc1ad)
label value sc1ad dummylb

fre sc1b
label variable sc1b "positive attitude toward police - without item 5"
label define sc1blb 1 "not true at all" 4 "very true"
label value sc1b sc1blb

fre sc1a
fre sc1b
fre sc1ad

/*
*fairness
fre c1_1f
fre c1_2
fre c1_7
gen sc1_fr = (c1_1f + c1_2 + c1_7)/3

*obligation to obey
fre c1_4f
fre c1_6
gen sc1_oby = (c1_4f + c1_6)/2

*moral alignement with police
fre c1_3f
fre c1_5

gen sc1_mrl = (c1_3f + c1_5)/2
fre c1_5 c1_3f if a1==0
fre c1_5 c1_3f if a1==1
*/

******** ******** ******** ******** ******** ******** 
*** vicexp (vicarious experiences)
* poly scales !!!

fre c2_1 c2_2
gen vicexp1 = c2_1r
gen vicexp2 = c2_2r
recode vicexp1 vicexp2 (0=1) (1=2) (2=3)

lab var vicexp1 "I witnessed it myself"  
lab var vicexp2 "Somebody reported me to have been treated with disrespect"

lab define vicexplb 1"no, never" 2 "yes, once" 3 "yes, many times"
label value vicexp1 vicexplb
label value vicexp2 vicexplb

fre vicexp1 vicexp2


foreach v of var vicexp1 vicexp2 {
	recode `v' (99=.)
}

*mean scale dependend variable instead of factor variable
capture drop svicexp
egen svicexp=rowmean(vicexp1 vicexp2)

lab var svicexp "mean vicarious experiences (higher=worse)"


fre sc2 sc2k

label variable sc2 "experiences with police disrespect"
label variable sc2k "experiences with police disrespect - categorical"
label define sc2klb 0 "none" 1 "once" 2 "several times"
label value sc2k sc2klb

recode sc2k (2=1), gen(sc2d)
label variable sc2d "experiences with police disrespect - dummy"
label value sc2d pcntdlb

******** ******** ******** ******** ******** ******** 
***pbeh (police behavior)
* poly scales !!!
fre c11_1r c11_2r c11_3r c11_4_1r c11_4_2r

gen pbeh1 = c11_1r
gen pbeh2 = c11_2r
gen pbeh3 = c11_3r
gen pbeh4 = c11_4_1r

lab var pbeh1 "The police have explained honestly the reasons for their action"
lab var pbeh2 "The police treated me/us fairly and with respect"
lab var pbeh3 "The police tried to provoke or offend"
lab var pbeh4 "The police became violent"

*label define pbehlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
*label value pbeh1-pbeh4 pbehlb
fre pbeh1 pbeh2 pbeh3 pbeh4

******** ******** ******** ******** ******** ******** 
***ybeh (youth behavior)
fre c12_1r c12_2r c12_3r c12_4r c12_5r c12_6_2r

gen ybeh1 = c12_1r
gen ybeh2 = c12_2r
gen ybeh3 = c12_3r
gen ybeh4 = c12_4r
gen ybeh5 = c12_5r
gen ybeh6 = c12_6_1r

lab var ybeh1 "you behaved normally and orderly"
lab var ybeh2 "you had drunk alcohol"
lab var ybeh3  "you resisted the police"
lab var ybeh4 "you provoked the police"
lab var ybeh5 "you ran away"
lab var ybeh6 "for other reasons"

label define ybehlb 0 "no" 1 "yes"
lab value ybeh1-ybeh6 ybehlb
fre ybeh1 ybeh2 ybeh3 ybeh4 ybeh5 ybeh6

******** ******** ******** ******** ******** ******** 
*** intermmt (moment of interaction)
fre c5
gen intermmt = c5
label var intermmt "moment of interaction"
label define intermmtlb 1 "morning" 2 "afternoon" 3"evening" 4 "night"
label value intermmt intermmtlb

******** ******** ******** ******** ******** ******** 
*** interyth presence of other people
fre c6
gen interyth = c6
label var interyth "presence of other people"
label define interythlb 1 "alone" 2 "with other youth" 3"with other adult people"
label value interyth interythlb

******** ******** ******** ******** ******** ******** 
*** interplc place of interaction
fre c7 
gen interplc = c7
label var interplc "place of interaction"
label define interplclb 1 "own neighborhood" 2 "city centre" 
label value interplc interplclb

******** ******** ******** ******** ******** ******** 
*** pact (action police)
fre c10_1r-c10_7r

gen pact1 = c10_1r
gen pact2 = c10_2r
gen pact3 = c10_3r
gen pact4 = c10_4r
gen pact5 = c10_5r
gen pact6 = c10_6r
gen pact7 = c10_7r

lab var pact1 "The police have checked my cloths/bags"
lab var pact2 "The police have checked my identity"
lab var pact3  "The police deecred an order to move"
lab var pact4 "The police took me to the police station"
lab var pact5 "I had to stay at the police station/asylum overnight"
lab var pact6 "The police spoke with my parents"
lab var pact7 "The police initiated a criminal proceeding"

label define pactlb 0 "no" 1 "yes"
lab value pact1-pact7 pactlb

******** ******** ******** ******** ******** ******** 
**szenario
** poly scales !!!
label var d6_1 "mobile stolen: tell parents"
label var d6_2 "mobile stolen: inform police" 
label var d6_3 "mobile stolen: confront perpetrators (if necessary by the use of violence" 
label var d6_4 "mobile stolen: talk with perpetrators" 
label var d6_5 "mobile stolen: do nothing"
label var d6_1f  "mobile stolen: tell parents - flip"
label var d6_2f "mobile stolen: inform police - flip"                   
label var d6_3f "mobile stolen: confront perpetrators (if necessary by the use of violence - flip"                          
label var d6_4f "mobile stolen: talk with perpetrators - flip"                      
label var d6_5f "mobile stolen: do nothing - flip"  

label var d7_1  "brother threatened: tell parents"
label var d7_2  "brother threatened: inform school" 
label var d7_3  "brother threatened: inform police" 
label var d7_4  "brother threatened: confront perpetrators (if necessary by the use of violence" 
label var d7_5  "brother threatened: talk with perpetrators" 
label var d7_6  "brother threatened: do nothing"
label var d7_1f "brother threatened: tell parents - flip"
label var d7_2f "brother threatened: inform school - flip"  
label var d7_3f "brother threatened: inform police - flip"                   
label var d7_4f "brother threatened: confront perpetrators (if necessary by the use of violence - flip"                          
label var d7_5f "brother threatened: talk with perpetrators - flip"                      
label var d7_6f "brother threatened: do nothing - flip"  
                   
label var sd67a "szenario call parents / school / police" 
label var sd67b "szenario call police" 
label var sd67c "szenario self-justice"

******************************** SAMPLE SELECTION ********************************
*replace xnons=3 if xtif=="72ZZL50000.tif"
fre xwn
fre xcity

*remove outliers
replace xnons=3 if kid==4039211 
replace xnons=3 if kid==1591416

*sample city
gen smplk=1 if xcity==1 & xnons!=3 
recode smplk (.=0)
gen smplm=1 if xcity==2 & xnons!=3 
recode smplm (.=0)

*sample module
gen smplp=1 if xmod==1 & xnons!=3 
recode smplp (.=0)
gen smpls=1 if xmod==2 & xnons!=3 
recode smpls (.=0)

*sample last contact
gen smpllc1=1 if  c3c12_filter>0 & c3c12_filter<3 & xnons!=3
recode smpllc1 (.=0)
gen smpllc2=1 if c3c12_filter > 0 & xnons!=3 
recode smpllc2 (.=0)
gen smpllc3=1 if c3c12_filter==1 & xnons!=3 
recode smpllc3 (.=0)

gen smplsex=1 if a1==1 & xnons!=3
replace smplsex=0 if a1==0 & xnons!=3

gen smplethnic=1 if a4f2d==1 & xnons!=3
replace smplethnic=0 if a4f2d==0 & xnons!=3

fre smplp
fre smpls
fre smplk
fre smplm

fre smpllc1
fre smpllc2

save "../../STATAfiles/S11DE_version4.dta", replace
compress

log close


